package com.haierp.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;

import com.baomidou.framework.service.impl.SuperServiceImpl;
import com.haierp.mapper.BuySiteDetailMapper;
import com.haierp.model.BuySiteDetail;
import com.haierp.service.IBuySiteDetailService;
import com.haierp.util.JsonPageResult;
import com.haierp.vo.BuySiteDetailQueryVO;

@Service("buySiteDetailService")
public class IBuySiteDetailServiceImpl extends SuperServiceImpl<BuySiteDetailMapper, BuySiteDetail>implements IBuySiteDetailService {
    protected Logger logger = LogManager.getLogger(getClass());

	@Override
	public void addBuySiteDetail(BuySiteDetail buySiteDetail) {
		this.baseMapper.insertSelective(buySiteDetail);
	}

	@Override
	public void updateBuySiteDetail(BuySiteDetail buySiteDetail) {
		this.baseMapper.updateSelectiveById(buySiteDetail);
	}

	@Override
	public BuySiteDetail queryBuySiteDetail(Long id) {
		return this.baseMapper.selectById(id);
	}

	@Override
	public JsonPageResult<List<BuySiteDetail>> queryBuySiteDetail(BuySiteDetailQueryVO buySiteDetailQueryVO) {
		JsonPageResult<List<BuySiteDetail>> itemResult = new JsonPageResult<>();
		//1、查询总的记录数量
		Integer totalCount =  this.baseMapper.queryBuySiteDetailCount(buySiteDetailQueryVO);
		
		//2、查询分页记录
		if(totalCount!=null&&totalCount!=0){
			itemResult.buildPage(totalCount, buySiteDetailQueryVO);
			List<BuySiteDetail> buySiteDetail = this.baseMapper.queryBuySiteDetails(buySiteDetailQueryVO);
			itemResult.setData(buySiteDetail);
		}else{
			List<BuySiteDetail> buySiteDetail  = new ArrayList<>();
			itemResult.setData(buySiteDetail);
		}
		return itemResult;
	}
	
	

	

}
